package net.betou.common.web.session;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * HttpSession提供类
 */
public class HttpSessionProvider implements SessionProvider{

	public Serializable getAttribute( HttpServletRequest request, String name ) {
		HttpSession session = request.getSession( false );
		if( session != null ){
			return ( Serializable ) session.getAttribute( name );
		}else{
			return null;
		}
	}

	public void setAttribute( HttpServletRequest request, HttpServletResponse response, String name, Serializable value ) {
		HttpSession session = request.getSession( );
		session.setAttribute( name, value );
	}

	public String getSessionId( HttpServletRequest request, HttpServletResponse response ) {
		return request.getSession( ).getId( );
	}

	public void logout( HttpServletRequest request, HttpServletResponse response ) {
		HttpSession session = request.getSession( false );
		if( session != null ){
			session.invalidate( );
		}
	}
}
